package com.health.db.dao.sm.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.SqlSession;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.health.db.dao.ServiceInterface;
import com.health.db.dao.sm.IRedisSentinelTemplateDao;
import com.health.db.mapper.RedisSentinelTemplateMapper;
import com.health.db.model.RedisSentinelTemplate;
import com.health.redis.RedisConstants;
 

@Component("redisSentinelTemplateDao")
public class RedisSentinelTemplateDaoImpl extends ServiceInterface implements IRedisSentinelTemplateDao  {
	private static final Logger _logger = Logger.getLogger(RedisSentinelTemplateDaoImpl.class);
	public List<Map<String, Object>> redisList = null;

	
	@Autowired
	RedisSentinelTemplateMapper redisSentinelTemplateMapper ;

	public  List<RedisSentinelTemplate> getRedisSentinelTemplate(String bigGroups) {
		
		String sql = "SELECT template_code,template_name,big_group,msg_type,regex,master_name,sentinel_properties,pool_properties " +
				" FROM redis_sentinel_template where big_group in ("
				+ bigGroups + ")";
		
		String key =RedisConstants.RedisSentinelTemplateMapper+ "_"+"selectByCondition_"+bigGroups;

		List vList  = new ArrayList<RedisSentinelTemplate>();
		 
		//Object object =PushDataTemplateFactory.getInstanse().getListObject(key,VersionControl.class); 
		Object object = null;
		if(null!=redisOperatiorLogic && redisOperatiorLogic.isJedisIsConnected())
		{	
			try
			{
				object = redisOperatiorLogic.readObject(key, getOrderRedisGroupNo("1"));
			
			} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			}
		}
	
	 
		if(null!=object&&!object.equals("")){
			vList =  (List) object;
		}
		else
		{
		 
				//RedisSentinelTemplateMapper redisSentinelTemplateMapper = sqlSession.getMapper(RedisSentinelTemplateMapper.class);
				  
				vList=redisSentinelTemplateMapper.getRedisSentinelTemplate(bigGroups);
		 
			//	PushDataTemplateFactory.getInstanse().setObject(key,vList);
		}
	
		return vList;
		
		 
	}
	
	
	public List<Map<String, Object>> getRedisList(SqlSession sqlSession) {
		return redisList;
	}

	public void setRedisList(SqlSession sqlSession,List<Map<String, Object>> redisList) {
		this.redisList = redisList;
	}


	@Override
	public List<RedisSentinelTemplate> getRedisTemplate() {
		// TODO Auto-generated method stub
		return null;
	}


	public RedisSentinelTemplateMapper getRedisSentinelTemplateMapper() {
		return redisSentinelTemplateMapper;
	}


	public void setRedisSentinelTemplateMapper(
			RedisSentinelTemplateMapper redisSentinelTemplateMapper) {
		this.redisSentinelTemplateMapper = redisSentinelTemplateMapper;
	}
	 
	
}
